﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WaiGaoQiaoWeb.Models;
using Model.WaiGaoQiao;
using WaiGaoQiaoWeb.JsonEntities;

namespace WaiGaoQiaoWeb.Controllers
{
    public class GasController : Controller
    {

        Work_GasInfo gas = new Work_GasInfo();

        //
        // GET: /Gas/

        public ActionResult Index()
        {
           
            ViewBag.QueryTime=GetQueryTime();//早晚班
            return View();
        }
       //转到添加修改界面
        public ActionResult Add()
        {
            ViewBag.ItemType = GetItemType();//燃气类型
            return View();
        }
        /// <summary>
        /// 获取新添加或修改的燃气录入的数据列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetGasData()
        {
            return Json(false);
        }
        /// <summary>
        /// 获取数据列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetDetailList(PageVM pvm)
        {
           
            string condition = pvm.query;//"and OrderNo = '" + pvm.query + "'";
            JsonFlexiGridData jsonFlexiGridData = new JsonFlexiGridData();
            jsonFlexiGridData.page = pvm.page;
            jsonFlexiGridData.total = gas.GetWork_GasCount(condition);

            IList<Work_GasInfo> splist = gas.GetAllCon_Gas(condition,pvm.rp, pvm.page);
            List<string> v;
            foreach (Work_GasInfo ida in splist)
            {
                #region
                v = new List<string>();
                v.Add(ida.ID.ToString());
                v.Add(ida.CBDT.ToString());
                v.Add(ida.GroupNo.ToString());
                v.Add(ida.GroupMan.ToString());
                v.Add(ida.MachNo.ToString());
                v.Add(ida.OpenMachDt.ToString());
                v.Add(ida.StopMachDt.ToString());
                v.Add(ida.RanqiType.ToString());
                v.Add(ida.TeamNo.ToString());
                v.Add(ida.StartTime.ToString());
                v.Add(ida.OneTime.ToString());
                v.Add(ida.TwoTime.ToString());
                v.Add(ida.ThreeTime.ToString());
                v.Add(ida.FourTime.ToString());
                v.Add(ida.FiveTime.ToString());
                v.Add(ida.SixTime.ToString());
                v.Add(ida.SevenTime.ToString());
                v.Add(ida.EightTime.ToString());
                v.Add(ida.NineTime.ToString());
                v.Add(ida.TenTime.ToString());
                v.Add(ida.ElevenTime.ToString());
                #endregion
                FlexiGridRow fgr = new FlexiGridRow()
                {
                    id = ida.ID.ToString(),
                    cell = v
                };
                jsonFlexiGridData.rows.Add(fgr);
            }
            return Json(jsonFlexiGridData);
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        public JsonResult SaveGas(GasVM vm)
        {
            return Json(true);
        }
        //获取燃气类型
        public IList<SelectListItem> GetItemType()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, "采暖");
            dic.Add(2, "制冷");
            IList<SelectListItem> selectList =
             dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }
        //早晚班
        public IList<SelectListItem> GetQueryTime()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, "早班");
            dic.Add(2, "晚班");
            IList<SelectListItem> selectList =
             dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        } 
    }
}
